package cn.example.vip.mall.util;

import java.io.Serializable;

public class RespResult<T> implements Serializable {
	private Integer code;
	private String msg;
	private T data;
	
	/**
	 * 响应消息
	 */
	public RespResult() {}
	
	public RespResult(RespCode respCode) {
		this.code = respCode.getCode();
		this.msg = respCode.getMsg();
	}
	
	public RespResult(RespCode respCode, T data) {
		this.code = respCode.getCode();
		this.msg = respCode.getMsg();
		this.data = data;
	}
	
	public static RespResult ok() {
		return new RespResult(RespCode.SUCCESS);
	}
	
	public static RespResult ok(Object data) {
		return new RespResult(RespCode.SUCCESS, data);
	}
	
	public static RespResult error(){
		return new RespResult(RespCode.ERROR, null);
	}
	
	public static RespResult error(Object data){
		return new RespResult(RespCode.ERROR, data);
	}
	
	public static RespResult error(Integer code, String msg){
		return secByError(code, msg);
	}
	
	/**
	 * 自定义异常
	 */
	public static RespResult secByError(Integer code, String msg){
		RespResult respResult = new RespResult();
		respResult.code = code;
		respResult.msg = msg;
		return respResult;
	}
	
	public Integer getCode() {
		return code;
	}
	
	public void setCode(Integer code) {
		this.code = code;
	}
	
	public String getMsg() {
		return msg;
	}
	
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	public T getData() {
		return data;
	}
	
	public void setData(T data) {
		this.data = data;
	}
}
